<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Upper</title>
    <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>

<body>

<script src="js/jquery-2.0.3.min.js"></script>
<script src="dwr/engine.js"></script>
<script src="dwr/util.js"></script>
<script src="dwr/interface/controller.js"></script>
<script src="js/bootstrap.min.js"></script>

<script type="text/javascript">

function adicionar() {
	
	var id = parseInt(document.getElementById("transactionIndex").value);

	$("#tblTransacoes").append('<tr valign="center" id="row' + id + '"><td><input type="text" name="transacoesNome" size="15" maxlength="60" tabindex="1" id="accessKey"></td><td><input type="text" name="transacoesMaxTime" size="15" maxlength="60" tabindex="1" id="accessKey"></td><td><input type="button" class="btn btn-danger" onclick="javascript:remover(' + id + ')" value="Remover" /></td></tr>');
	
	id = id + 1;
	document.getElementById("transactionIndex").value = id + "";
	
}

function remover(index) {
	var linha = "#row" + index;
	$(linha).remove();	
}

function teste() {
	controller.teste({callback: function(retorno) { alert(retorno);}});
}

function runTest() {
	$("#formTest").attr("action","/upper/test.action");
	$("#formTest").submit();
}

</script>

<s:form id="formTest" name="formTest" action="config" cssClass="form-horizontal">

<div class="navbar navbar-inverse">
  <div class="navbar-inner">
    <a class="brand" href="<s:url action='index' />">Upper</a>
    <ul class="nav">
      <li class="active"><a href="<s:url action='index' />">Configuração</a></li>
      <li><a href="#">Teste</a></li>
    </ul>
  </div>
</div>

<h3>Configuração</h3>

<div class="table">
  <ul class="nav nav-tabs">
    <li class="active"><a href="#tab1" data-toggle="tab">Geral</a></li>
    <li><a href="#tab2" data-toggle="tab">Teste</a></li>
    <li><a href="#tab3" data-toggle="tab">Transações</a></li>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="tab1">      
		<div class="control-group">
		  	<label class="control-label" for="accessKey">AWS Access Key:</label>
		  	<div class="controls">
		  	<s:textfield id="accessKey" name="configuration.accessKey" size="30" maxlength="60" tabindex="1" value="%{configuration.accessKey}" />
		  	</div>
		</div>
		<div class="control-group">
		  	<label class="control-label" for="secretKey">AWS Secret Key:</label>
		  	<div class="controls">
		  	<s:textfield id="secretKey" name="configuration.secretKey" size="30" maxlength="60" tabindex="1" value="%{configuration.secretKey}"/>
		  	</div>
		</div>  
		<div class="control-group">
		  	<label class="control-label" for="imageId">AWS Image Id:</label>
		  	<div class="controls">
		  	<s:textfield id="imageId" name="configuration.imageId" size="30" maxlength="60" tabindex="1" value="%{configuration.imageId}"/>
		  	</div>
		</div> 
		<div class="control-group">
		  	<label class="control-label" for="snapShotId">AWS Snapshot Id:</label>
		  	<div class="controls">
		  	<s:textfield id="snapShotId" name="configuration.snapShotId" size="30" maxlength="60" tabindex="1" value="%{configuration.snapShotId}"/>
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="keyName">AWS Key Name:</label>
		  	<div class="controls">
		  	<s:textfield id="keyName" name="configuration.keyName" size="30" maxlength="60" tabindex="1" value="%{configuration.keyName}"/>
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="securityGroupId">AWS Security Group Id:</label>
		  	<div class="controls">
		  	<s:textfield id="securityGroupId" name="configuration.securityGroupId" size="30" maxlength="60" tabindex="1" value="%{configuration.securityGroupId}"/>
		  	</div>
		</div>						
		<div class="control-group">
		  	<label class="control-label" for="jMeterDirectory">Diretório instalação JMeter:</label>
		  	<div class="controls">
		  	<s:textfield id="jMeterDirectory" name="configuration.jMeterDirectory" size="30" maxlength="60" tabindex="1" value="%{configuration.jMeterDirectory}"/>
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="testPlanPath">Caminho do Plano de Testes:</label>
		  	<div class="controls">
		  	<s:textfield id="testPlanPath" name="configuration.testPlanPath" size="30" maxlength="60" tabindex="1" value="%{configuration.testPlanPath}"/>
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="instanceType">Tipo de instância para teste:</label>
		  	<div class="controls">
			<s:select tabindex="2" id="instanceType" list="instanceTypes" 
						name="configuration.instanceType.id" listKey="id" listValue="name"
						value="%{configuration.instanceType.id}"/>
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="findBestInstanceType">Buscar melhor instância:</label>
		  	<div class="controls">		  	
			<s:checkbox id="findBestInstanceType" name="configuration.findBestInstanceType" value="%{configuration.findBestInstanceType}" />  	
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="volumeType">Tipo de Volume</label>
		  	<div class="controls">
			<s:select tabindex="2" id="volumeType" list="volumeTypes" 
			name="volumeTypeValue" listKey="value" listValue="name"
			value="%{configuration.volumeType.value}"/>		
		  	</div>
		</div>	
		<div class="control-group">
		  	<label class="control-label" for="provisionedIOPs">IOPs provisionado</label>
		  	<div class="controls">
			<s:textfield id="provisionedIOPs" name="configuration.provisionedIOPS" size="20" maxlength="20" tabindex="1" value="%{configuration.provisionedIOPS}"/>	
		  	</div>
		</div>		
    </div>
    
    <div class="tab-pane" id="tab2">
    	<div class="control-group">
		<table class="table table-condensed">
			<thead>
				<tr>
					<th>
						
					</th>
					<th>
						Valor
					</th>
					<th>
						Propriedade
					</th>					
				</tr> 
			</thead>
			<tbody>
			
			<tr>
				<td>
					<label class="control-label" for="numThreads">Nº Threads:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="numThreads" name="configuration.numThreads" size="15" maxlength="60" tabindex="1" value="%{configuration.numThreads}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="numThreadsJMeterKey" name="configuration.numThreadsJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.numThreadsJMeterKey}"/>
				</td>					
			</tr> 
		
			
			<tr>
				<td>
					<label class="control-label" for="initTime">Tempo de inicialização:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="initTime" name="configuration.initTime" size="15" maxlength="60" tabindex="1" value="%{configuration.initTime}"/>
					</div>					
				</td>
				<td>											
					<s:textfield id="initTimeJMeterKey" name="configuration.initTimeJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.initTimeJMeterKey}"/>
				</td>					
			</tr> 
			
			
			<tr>
				<td>
					<label class="control-label" for="iterations">Iterações:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="iterations" name="configuration.iterations" size="15" maxlength="60" tabindex="1" value="%{configuration.iterations}"/>
					</div>					
				</td>
				<td>					
					<s:textfield id="iterations" name="configuration.iterationsJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.iterationsJMeterKey}"/>
				</td>					
			</tr> 
			
			
			<tr>
				<td>
					<label class="control-label" for="logTransactionsPath">Log de transações:</label>					
				</td>
				<td>	
					<div class="controls">				
						<s:textfield id="logTransactionsPath" name="configuration.logTransactionsPath" size="15" maxlength="80" tabindex="1" value="%{configuration.logTransactionsPath}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="logTransactionsPathKey" name="configuration.logTransactionsPathKey" size="10" maxlength="80" tabindex="1" value="%{configuration.logTransactionsPathKey}"/>
				</td>					
			</tr> 
				
			
			<tr>
				<td>
					<label class="control-label" for=logResourcesPath>Log de recursos:</label>					
				</td>
				<td>	
					<div class="controls">				
						<s:textfield id="logResourcesPath" name="configuration.logResourcesPath" size="15" maxlength="80" tabindex="1" value="%{configuration.logResourcesPath}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="logResourcesPath" name="configuration.logResourcesPathKey" size="10" maxlength="80" tabindex="1" value="%{configuration.logResourcesPathKey}"/>
				</td>					
			</tr> 
			
			
			<tr>
				<td>
					<label class="control-label" for="dbUrl">DB Url:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbUrl" name="configuration.dbUrl" size="15" maxlength="60" tabindex="1" value="%{configuration.dbUrl}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbURLJMeterKey" name="configuration.dbURLJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbURLJMeterKey}"/>
				</td>					
			</tr> 
				
			
			<tr>
				<td>
					<label class="control-label" for="dbDriver">DB Driver:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbDriver" name="configuration.dbDriver" size="15" maxlength="60" tabindex="1" value="%{configuration.dbDriver}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbDriverJMeterKey" name="configuration.dbDriverJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbDriverJMeterKey}"/>
				</td>					
			</tr> 
			
			
			<tr>
				<td>
					<label class="control-label" for="dbUser">DB User:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbUser" name="configuration.dbUser" size="15" maxlength="60" tabindex="1" value="%{configuration.dbUser}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbUserJMeterKey" name="configuration.dbUserJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbUserJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="dbPassword">DB Password:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbPassword" name="configuration.dbPassword" size="15" maxlength="60" tabindex="1" value="%{configuration.dbPassword}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbPasswordJMeterKey" name="configuration.dbPasswordJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbPasswordJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="dbMaxConn">DB Maximo Conexões:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbMaxConn" name="configuration.dbMaxConn" size="15" maxlength="60" tabindex="1" value="%{configuration.dbMaxConn}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbMaxConnJMeterKey" name="configuration.dbMaxConnJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbMaxConnJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="dbTimeOutGroup">DB Timeout Group:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbTimeOutGroup" name="configuration.dbTimeOutGroup" size="15" maxlength="60" tabindex="1" value="%{configuration.dbTimeOutGroup}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbTimeOutGroupJMeterKey" name="configuration.dbTimeOutGroupJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbTimeOutGroupJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="dbCleanIdleInterval">DB Clean Interval:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbCleanIdleInterval" name="configuration.dbCleanIdleInterval" size="15" maxlength="60" tabindex="1" value="%{configuration.dbCleanIdleInterval}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbCleanIdleIntervalJMeterKey" name="configuration.dbCleanIdleIntervalJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbCleanIdleIntervalJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="dbConnTimeout">DB Connection Timeout:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbConnTimeout" name="configuration.dbConnTimeout" size="15" maxlength="60" tabindex="1" value="%{configuration.dbConnTimeout}"/>			
					</div>					
				</td>
				<td>
					<s:textfield id="dbConnTimeoutJMeterKey" name="configuration.dbConnTimeoutJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbConnTimeoutJMeterKey}"/>
				</td>					
			</tr> 

			<tr>
				<td>
					<label class="control-label" for="numThreads">DB Test Query:</label>					
				</td>
				<td>	
					<div class="controls">				
					<s:textfield id="dbTestQuery" name="configuration.dbTestQuery" size="15" maxlength="60" tabindex="1" value="%{configuration.dbTestQuery}"/>
					</div>					
				</td>
				<td>
					<s:textfield id="dbTestQueryJMeterKey" name="configuration.dbTestQueryJMeterKey" size="10" maxlength="60" tabindex="1" value="%{configuration.dbTestQueryJMeterKey}"/>
				</td>					
			</tr> 
																									
																					
			</tbody>		
		</table>
		
			</div>									
    </div>
    <div class="tab-pane" id="tab3">
    	
    	<table class="table table-condensed" id="tblTransacoes">
    		<thead>
    			<th>
    				Transação
    			</th>
    			<th>
    				Tempo max execução(ms)
    			</th>    	
    			<th>
    				<input type="button" class="btn btn-primary"  onclick="javascript:adicionar();" value="+Adicionar transação" />
    			</th>		
    		</thead>
    		<tbody>
    			    	
			<s:iterator value="configuration.transactions" status="contador" >
				<tr id="row<s:property value='%{#contador.index}' />">
					<td>
						<s:textfield id="accessKey" name="transacoesNome" size="15" maxlength="60" tabindex="1" value="%{nome}"/>
					</td>
					<td>
						<s:textfield id="accessKey" name="transacoesMaxTime" size="15" maxlength="60" tabindex="1" value="%{timeExecution}"/>
					</td>
					<td>
						<input type="button" class="btn btn-danger" onclick="javascript:remover(<s:property value='%{#contador.index}' />)" value="Remover" />
					</td>					
				</tr> 						
			</s:iterator>  
			</tbody>  		
    	</table>
    </div>    
  </div>
  
    <ul class="nav nav-tabs">

  </ul>
  
</div>
<div style="text-align: center;">
  		<input type="submit" name="salvar" id="salvar" class="btn btn-inverse" 
		value="Salvar" title="Salvar" style="cursor: pointer;" />
		
		<input type="button" name="teste" id="teste" class="btn btn-inverse"  
		onclick="javascript:runTest();" value="Iniciar Teste!" 
		title="Iniciar Teste" style="cursor: pointer;" />
</div>
<s:hidden id="transactionIndex" value="%{configuration.transactions.size}" />
</s:form>
</body>
</html>
